#!/usr/bin/python
import cgitb
cgitb.enable()
from re import findall 
from re import compile
import cgi 
import os

print "Content-type: text/html"
print 

class re_c:
    def __init__(self,string):
        self.string = string
    def re_cal (self):
        moudle = compile('(#[0-9a-fA-F]{6})')
        return findall(moudle,self.string)
    def re_cal_2 (self):
        moudle = compile('(<!--[*]{1,10}-->)')
        moudle2 =  compile('([^name=])')
        partion =  findall(moudle,self.string)
        result =  [re.findall(moudle2,item) for item in partion]
        return result

class color:
    def __init__(self,path):
        self.color_file = open (path,"r")
        self.Glob = []
        self.Color_name = []
        for line in color_file:
            my_re = re_c(line)
            self.Glob+= my_re.re_cal(line)
            self.Color_name += my_re.re_cal_2(line)
    def print_style(self):
        print """
        <style type="text/css">
        """
        for i in range(0,len(self.Glob)):
            print "div#container"+str(i)+ " {width:100 ;height:70;background-color:"+self.Glob[i] + ";float:left;}"
        print """</style>"""
    def print_div(self):
        for i in range(0,len(Color_name)):
            print "<div id=\"container"+str(i)+"\" align=\"center\" >"+Color_name[i]+"</div>"

if __name__ == "__main__":
    print "current : %s" % (os.getcwd())
    path = raw_input("Output path > ")
    output = open (path,"w")
    path_color = os.getcwd()+"color.txt"
    my_color_html = color(path_color)
    head =  """
    <html>
    <head>"""
    style =  my_color_html.print_style()
    link1 =  "</head><body>"
     div =  my_color_html.print_div()
    end =  "</body></html>"
    output.writeline(head)
    output.writeline(style)
    output.writeline(link1)
    output.writeline(div)
    output.writeline(end)
    output.close()
    
